use config::{Config, ConfigError, File};
use log::debug;
use serde_derive::Deserialize;

#[derive(Debug, Deserialize)]
pub struct Account {
    pub username: String,
    pub password: String,
}

#[derive(Debug, Deserialize)]
pub struct Settings {
    pub account: Account,
}

impl Settings {
    pub fn new() -> Result<Self, ConfigError> {
        let s = Config::builder()
            .add_source(File::with_name("config/app.toml"))
            .build()?;

        debug!("username: {}", s.get::<String>("account.username").unwrap());
        debug!("password: {}", s.get::<String>("account.password").unwrap());

        s.try_deserialize()
    }
}
